package ${package};

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
<#if (isAPI=='false')>
import org.springframework.web.servlet.ModelAndView;
</#if>

import ${baseActionPackage};
import ${resultJsonPackage};
import ${modelPackage};
import ${servicePackage};
import com.tmsps.ne4spring.page.Page;

/**
 * @title ${className?cap_first}Action.java
 * @package ${package}
 * @description ${description}Action
 * @author ${author}
 * @date ${creatTime?string("yyyy-MM-dd")}
 * @version V1.0
 * @Copyright ${creatTime?string("yyyy")} nuoyun All rights reserved.
 */
@Controller
@Scope("prototype")
@RequestMapping("${requestPrefix}/${tableSubName?uncap_first}/")
public class ${className?cap_first}Action extends BaseAction {

	@Autowired
	private ${className?cap_first}Service ${className?uncap_first}Service;
	
	<#if (isAPI=='false')>
	/**
	 * @title ${tableSubName?uncap_first}ListView
	 * @description ${description}列表
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * return String
	 */
	@GetMapping(value = "${tableSubName?uncap_first}ListView")
	public ModelAndView ${tableSubName?uncap_first}ListView() {
		ModelAndView mv = new ModelAndView("${requestPrefix}/${tableSubName?uncap_first}/${tableSubName?uncap_first}List");
		return mv;
	}
	</#if>
	/**
	 * @title get${tableSubName?cap_first}ListData
	 * @description 获取${description}列表数据
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * return String
	 */
	@GetMapping(value = "get${tableSubName?cap_first}ListData")
	public @ResponseBody String get${tableSubName?cap_first}ListData() {
		Page data = ${className?uncap_first}Service.get${tableSubName?cap_first}ListData(page,srh);
		return ResultJson.getResultPassOk(data);
	}
	<#if (isAPI=='false')>
	/**
	 * @title ${tableSubName?uncap_first}Add
	 * @description 新增${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * return ModelAndView
	 */
	@GetMapping(value = "${tableSubName?uncap_first}Add")
	public ModelAndView ${tableSubName?uncap_first}Add() {
		ModelAndView mv = new ModelAndView("${requestPrefix}/${tableSubName?uncap_first}/${tableSubName?uncap_first}Add");
		return mv;
	}
	
	/**
	 * @title ${tableSubName?uncap_first}Edit
	 * @description 编辑${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param id ${tableSubName} id
	 * return ModelAndView
	 */
	@GetMapping(value = "${tableSubName?uncap_first}Edit")
	public ModelAndView ${tableSubName?uncap_first}Edit(String id) {
		ModelAndView mv = new ModelAndView("${requestPrefix}/${tableSubName?uncap_first}/${tableSubName?uncap_first}Edit");
		${tableName} detail = ${className?uncap_first}Service.get${tableSubName?cap_first}Model(id);
		mv.addObject("detail", detail);
		return mv;
	}
	</#if>
	<#if (saveorupdate=='true')>
	/**
	 * @title saveOrUpdate
	 * @description 保存、编辑${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param model
	 * return String
	 */
	@PostMapping(value = "saveOrUpdate")
	public @ResponseBody String saveOrUpdate(${tableName} model) {
		boolean result = ${className?uncap_first}Service.saveOrUpdate(model);
		return ResultJson.getResult(result);
	}
	</#if>
	
	<#if (saveorupdate!='true')>
	/**
	 * @title save
	 * @description 新增${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param model ${tableName}
	 * return String
	 */
	@PostMapping(value = "save")
	public @ResponseBody String save(${tableName} model) {
		boolean result = ${className?uncap_first}Service.save(model);
		return ResultJson.getResult(result);
	}
	
	/**
	 * @title update
	 * @description 修改${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param model ${tableName}
	 * return String
	 */
	@PostMapping(value = "update")
	public @ResponseBody String update(${tableName} model) {
		boolean result = ${className?uncap_first}Service.update(model);
		return ResultJson.getResult(result);
	}
	</#if>
	/**
	 * @title getDetail
	 * @description 获取${description}详细信息
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param id ${tableSubName} id
	 * return String
	 */
	@GetMapping(value = "getDetail")
	public @ResponseBody String getDetail(String id) {
		Map<String, Object> detail = ${className?uncap_first}Service.get${tableSubName?cap_first}Detail(id);
		return ResultJson.getResultPassOk(detail);
	}
	
	/**
	 * @title remove
	 * @description 删除${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param id ${description} id
	 * return String
	 */
	@PostMapping(value = "remove")
	public @ResponseBody String remove(String id) {
		boolean result = ${className?uncap_first}Service.remove(id);
		return ResultJson.getResult(result);
	}
	<#if (batch=='true')>
	/**
	 * @title deleteBatch
	 * @description 批量删除${description}
	 * @author ${author}
	 * @date ${creatTime?string("yyyy-MM-dd")}
	 * @param ids ${description} id列表
	 * return String
	 */
	@PostMapping(value = "deleteBatch")
	public @ResponseBody String deleteBatch(String ids) {
		if (StrUtil.isBlank(ids)) {
			return ResultJson.getResultExParam();
		}
		String[] idsArr = ids.split(",");
		boolean result = ${className?uncap_first}Service.batchRemove(Arrays.asList(idsArr));
		return ResultJson.getResult(result);
	}
	</#if>
}